<?php

namespace System\Core;

use \System\Types;

abstract class View extends Engineer
{

    protected $_data = array();

    /**
     * @var \System\Lib\MasterPage
     */
    protected $_master;

    const PARSE_BRACKETS = 0;
    const PARSE_HTMLTAGS = 1;

    /**
     * @var \System\Lib\Parser
     */
    protected $_parser;

    public function __construct()
    {
        parent::__construct();
        $this->_parser = new \System\Lib\Parser($this);
        \System\Lib\Log::Write('View Class Loaded', \System\Lib\Log::DEBUG);
    }

    public function ParseType($type)
    {
        $l = '{';
        $r = '}';

        if ($type === self::PARSE_HTMLTAGS)
        {
            $l = '<';
            $r = '>';
        }

        $this->_parser->SetDelimiters($l, $r);
    }

    final public function AddOrUpdateData($name, $value)
    {
        $this->_data[$name] = $value;
    }

    public function CreateBuffer()
    {
        $this->_parser->Parse($this->_data);
    }

    final public function Dispose()
    {
        $disposed = parent::Dispose();

        if (!$disposed)
            $this->output->Display($this->CreateBuffer());

        return $disposed;
    }

    /**
     * @return \System\Lib\MasterPage
     */
    final public function &GetMaster()
    {
        return $this->_master;
    }

    final public function SetMaster(\System\Lib\MasterPage &$master = null)
    {
        $this->_master = $master;
    }

}
